package fmse.uaic.k.configuration_abstraction.data_structures;

import java.util.List;

import fmse.uaic.k.configuration_abstraction.abstract_classes.KAbstractNode;
import fmse.uaic.k.configuration_abstraction.abstract_classes.KAbstractTree;
import fmse.uaic.k.configuration_abstraction.exceptions.NotDeclaredLabelException;
import fmse.uaic.k.configuration_abstraction.visitors.CheckLabelDeclarationVisitor;

public class RuleKTree extends KAbstractTree {
	
	private RuleKNode root;
	private int line;
	
	public RuleKTree(RuleKNode root, int line_number) {
		super();
		this.root = root;
		line = line_number;
	}
	
	/**
	 * Check if there are labels in the rule which are not declared in a given configuration
	 * @param ctree
	 * @throws NotDeclaredLabelException
	 */
	public void checkLabelsDeclarations(ConfigurationKTree ctree) throws NotDeclaredLabelException
	{
		CheckLabelDeclarationVisitor declarationVisitor = new CheckLabelDeclarationVisitor(ctree);
		dfs(declarationVisitor);
		List<KAbstractNode> missingDeclarations = declarationVisitor.getUndefined();
		if (missingDeclarations.size() > 0)
			throw new NotDeclaredLabelException(root, line, missingDeclarations);
	}
	
	
}
